import sys
import os
from PySide6.QtWidgets import *
from PySide6.QtGui import *
from PySide6.QtCore import *

class Demo(QWidget):
    def __init__(self, parent=None):
        super().__init__(parent)
        self.parent = parent
        layout = QVBoxLayout()
        layout.setAlignment(Qt.AlignmentFlag.AlignTop)
        
        toolBar=QToolBar()

        btn=QPushButton('GetDouble')
        btn.clicked.connect(self.GetDouble)
        toolBar.addWidget(btn)

        btn=QPushButton('GetInt')
        btn.clicked.connect(self.GetInt)
        toolBar.addWidget(btn)

        btn=QPushButton('GetItem')
        btn.clicked.connect(self.GetItem)
        toolBar.addWidget(btn)

        btn=QPushButton('GetMultiLineText')
        btn.clicked.connect(self.GetMultiLineText)
        toolBar.addWidget(btn)

        btn=QPushButton('GetText')
        btn.clicked.connect(self.GetText)
        toolBar.addWidget(btn)

        layout.addWidget(toolBar)

        self.type=QLabel('type')
        layout.addWidget(self.type)
        self.label=QLabel('result')
        layout.addWidget(self.label)

        self.setLayout(layout)
    def GetDouble(self):
        num,ok=QInputDialog.getDouble(self,'Input Double','Input Double',value=3.01,
                                      minValue=1.00,maxValue=5.00,decimals=2,step=0.1)
        if ok:
            self.type.setText(f'Type:{type(num).__name__}')
            self.label.setText(f'Value:{str(num)}')
    def GetInt(self):
        num,ok=QInputDialog.getInt(self,'Input Int','Input Int',value=3,
                                      minValue=1,maxValue=20,step=2)
        if ok:
            self.type.setText(f'Type:{type(num).__name__}')
            self.label.setText(f'Value:{str(num)}')
    def GetItem(self):
        items=['C','C++','Java','Python','C#','JavaScript']
        item,ok=QInputDialog.getItem(self,'Select One Item','Language',items,4,False)
        if ok:
            self.type.setText(f'Type:{type(item).__name__}')
            self.label.setText(f'Value:{item}')
    def GetMultiLineText(self):
        text,ok=QInputDialog.getMultiLineText(self,'Input Text','Input Bak',text='描述')
        if ok:
            self.type.setText(f'Type:{type(text).__name__}')
            self.label.setText(f'Value:{text}')
    def GetText(self):
        text,ok=QInputDialog.getText(self,'Input Text','Input Name',text='zhangsan')
        if ok:
            self.type.setText(f'Type:{type(text).__name__}')
            self.label.setText(f'Value:{text}')
def runDemo(parent):
    wigdet =  Demo(parent)
    return wigdet